#pragma once

#include "graph_data.h"

namespace details
{
typedef size_t index_el_id_t;
typedef size_t bucket_id_t;

struct index_element_t
{
  vertex_id id;
};

struct index_bucket_t
{
  index_el_id_t start_id;
  index_el_id_t end_id;
};

struct index_header_t
{
  double lat_diff;
  double lon_diff;
  size_t bucket_count;
  index_bucket_t buckets[];
};

bucket_id_t get_bucket_id(vertex_data_t const & data, double lat_diff,
                      double lon_diff)
{
  size_t lon_count = 360. / lon_diff;
  size_t lat_count = 180. / lat_diff;
  return static_cast<bucket_id_t> ((data.lon + 180.) / lon_diff)
      + static_cast<bucket_id_t> ((data.lat + 90.) / lat_diff) * lon_count;
}
} // namespace details

struct data_index_t
{
  data_index_t(void * raw_data) :
    index_header_(raw_data)
  {
  }

  void build_index(graph_t const & graph, double lat_diff, double lon_diff)
  {
    index_header_->lat_diff = lat_diff;
    index_header_->lon_diff = lon_diff;

    size_t lon_count = 360. / lon_diff;
    size_t lat_count = 180. / lat_diff;
    index_header_->bucket_count = lat_count * lon_count;
    index_header_->
  }
private:
  details::index_header_t * index_header_;
};
